package com.suzaku.demo;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.szk.ads.open.base.SuZaKuError;
import com.szk.ads.open.cons.SzkOrientation;
import com.szk.ads.open.interfaces.IAdDisplayCallback;
import com.szk.ads.open.interfaces.IAdLoadCallback;
import com.szk.ads.open.slot.banner.SzkAdBanner;
import com.szk.ads.open.slot.fullv.SzkAdFullVideo;
import com.szk.ads.open.slot.reward.SzkAdRewardVideo;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Activity activity;
    private ViewGroup bannerContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.activity = this;
        findViewById(R.id.adv_reward_video).setOnClickListener(this);
        findViewById(R.id.adv_full_video).setOnClickListener(this);
        findViewById(R.id.adv_banner).setOnClickListener(this);
        bannerContainer = findViewById(R.id.banner_container);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.adv_reward_video:
                showRewardVideoAd();
                break;
            case R.id.adv_full_video:
                showFullVideoAd();
                break;
            case R.id.adv_banner:
                showBannerAd();
                break;
        }
    }


    private void showRewardVideoAd() {
        SzkAdRewardVideo rewardVideo = new SzkAdRewardVideo.Builder(activity)
                .setAdSlotId("947967275")
                .setUserID("u_1234")
                .setOrientation(SzkOrientation.VERTICAL)
                .setLoadCallback(loadCallback)
                .setDisplayCallback(displayCallback)
                .setRewardAmount(10)
                .setRewardName("金条")
                .build();
        rewardVideo.loadAndShow();
    }

    private void showFullVideoAd() {

        SzkAdFullVideo adFullVideo = new SzkAdFullVideo.Builder(activity)
                .setAdSlotId("947967273")
                .setOrientation(SzkOrientation.VERTICAL)
                .setLoadCallback(loadCallback)
                .setDisplayCallback(displayCallback)
                .setRewardAmount(20)
                .setRewardName("金条")
                .setUserID("u_1234")
                .build();
        adFullVideo.loadAndShow();
    }


    private void showBannerAd() {

        SzkAdBanner banner = new SzkAdBanner.Builder(activity)
                .setAdSlotId("947967274")
                .setImageAdSize(600,300)
                .setLoadCallback(loadCallback)
                .setDisplayCallback(displayCallback)
                .setContainer(bannerContainer)
                .build();
        banner.loadAndShow();
    }


    private void toast(String msg) {
        Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
    }

    private final IAdLoadCallback loadCallback = new IAdLoadCallback() {
        @Override
        public void onAdLoadFailed(SuZaKuError error) {
            toast("onAdLoadFailed:" + error.toString());
        }

        @Override
        public void onAdLoaded() {
            toast("onAdLoaded");
        }

        @Override
        public void onLoadWait() {
            toast("onWait");
        }
    };
    private final IAdDisplayCallback displayCallback = new IAdDisplayCallback() {
        @Override
        public void onAdLeftApplication() {
            toast("onAdLeftApplication");

        }

        @Override
        public void onAdClosed() {
            toast("onAdClosed");
        }

        @Override
        public void onAdClicked() {
            toast("onAdClicked");
        }

        @Override
        public void onAdShow() {
            toast("onAdShow");
        }

        @Override
        public void onAdShowFail(SuZaKuError error) {
            toast("onAdShowFail:" + error.toString());
        }

        @Override
        public void onAdComplete() {
            toast("onAdComplete");
        }

        @Override
        public void onAdSkip() {
            toast("onAdSkip");
        }
    };


}